﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;

namespace WindowsFormsApplication1
{
    class Account
    {
        private string usertype;
        private string password;
        private DBConnector connector;

        public Account()
        {
            connector = new DBConnector();
        }

        public void setUserType(String usertype)
        {
            this.usertype = usertype;
        }

        public string getPassword(String usertype)
        {
            string query = "SELECT userPass from account WHERE userType = \'" + usertype + "\'";
            if (connector.openConnection())
            {
                MySqlCommand cmd = new MySqlCommand(query, connector.getConnection());
                MySqlDataReader dataReader = cmd.ExecuteReader();
                if(dataReader.Read())
                    password = dataReader["userPass"] + "";
                dataReader.Close();
                connector.closeConnection();
                return password;
            }
            else
            {
                return "";
            }
        }

        public void updatePassword(String password)
        {
            string query = "UPDATE account SET userPass = \'" + password + "\' WHERE userType = \'" + usertype + "\'";
            if (connector.openConnection())
            {
                MySqlCommand cmd = new MySqlCommand();
                cmd.CommandText = query;
                cmd.Connection = connector.getConnection();
                cmd.ExecuteNonQuery();
                connector.closeConnection();
            }
        }
    }
}
